package com.migu.contacts.main.my;

import static com.migu.contacts.net.Service.API;

import android.content.pm.PackageManager;
import android.view.View;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ToastUtils;
import com.frank.libandroid.BaseActivity;
import com.frank.libandroid.HttpCallback;
import com.frank.libandroid.util.ImageUtil;
import com.migu.contacts.bean.Feedback;
import com.migu.contacts.databinding.ActivityAdviceBinding;
import com.migu.contacts.util.PictureUtil;

import java.util.ArrayList;

public class AdviceActivity extends BaseActivity<ActivityAdviceBinding> {
    @Override
    protected void initData() {
        super.initData();
        mBinding.setBean(feedback);
    }

    Feedback feedback = new Feedback();

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        for (int grantResult : grantResults) {
            if (grantResult != PackageManager.PERMISSION_GRANTED) {
                return;
            }
        }

    }

    public void changeAvatar(View view) {
        PictureUtil.choosePic(mActivity, 3, new PictureUtil.Callback() {
            @Override
            public void onSuccess(String url) {
                if (feedback.url == null) {
                    feedback.url = new ArrayList<>();
                    feedback.url.add(url);
                }
                ImageUtil.loadUrl(mBinding.avatar, url);
            }
        });
//
    }

    public void go(View view) {
        API.feedback(feedback).watch(this, new HttpCallback<Boolean>() {
            @Override
            protected void onSuccess(Boolean aBoolean) {
                if (aBoolean) {
                    ToastUtils.showShort("提交成功");
                    finish();
                }
            }
        });

    }
}